package com.qf.test.contller;

import com.qf.test.pojo.User;
import com.qf.test.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
//解决前后段分离
@CrossOrigin("*")
@RequestMapping("/user")
public class UserContller {
    @Autowired
    private UserService userService;

    //查询所有的用户
    @GetMapping("/list")
    public List<User> findAll() {
        List<User> list = userService.findAll();
        for (User user : list) {
            System.out.println(user);
        }
        return list;
    }

    //根据id进进行查询

    @GetMapping("/findid")
    public User findId(Integer id) {
        User user = userService.findId(id);
        return user;

    }

    /**
     * 添加一个用户
     */
    @PostMapping("/insert")
    public User inserto(@RequestBody User user) {
        User user1 = userService.insretinone(user);
        return user;
    }

    /**
     * 根据id删除一个用户
     */
    @PostMapping("/delete")
    public int deletedId(@RequestBody Integer id) {
        int count = userService.deleted(id);
        return count;


    }

    /**
     * 修改一个用户
     */
    @PostMapping("/update")
    private User  update(@RequestBody User user) {
        User user1 = userService.update(user);
        return user1;

    }
}
